package cate.game.play.config.buff;

import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.buff.BuffEnhanceCfg;
import cate.game.play.buff.BuffParam;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class BuffEnhance {

	@NoteField("附加概率")
	public int exAddChance;

	@NoteField("附加属性")
	public FightAttr exAttr = new FightAttr();

	@NoteField("附加回合")
	public int exRound;

	@NoteField("是否可被驱散")
	public Boolean dispel;

	@NoteField("无视抗控")
	public Boolean ignAntiCtrl;

	@NoteField("buff血量")
	public long buffHp;

	@NoteField("附加最大叠加数量")
	public int exPileMax;

	@NoteField("附加效果配置")
	public List<String> exEffectArgs;

	@NoteField("附加buff")
	public List<ExBuffCfg> exBuffs;

	public void handleCfg(BuffEnhanceCfg cfg) {
		addChance(cfg.exAddChance);
		addExAttr(cfg.exAttr);
		addExRound(cfg.exRound);
		setDispel(cfg.dispel);
		setIgnAntiCtrl(cfg.ignAntiCtrl);
		addBuffHp(cfg.buffHp);
		addExPileMax(cfg.exPileMax);
		addExEffectArgs(cfg.exEffectArgs);
		addExBuff(cfg.exBuffs);
	}

	public void handleParam(BuffParam param) {
		addExAttr(param.exAttr);
		addExRound(param.exRound);
		setDispel(param.dispel);
		setIgnAntiCtrl(param.ignAntiCtrl);
		addBuffHp(param.buffHp);
	}

	public void addChance(Integer exChance) {
		if (exChance == null) {
			return;
		}
		this.exAddChance += exChance;
	}

	public void addExAttr(FightAttr exAttr) {
		if (exAttr == null) {
			return;
		}
		this.exAttr.add(exAttr);
	}

	public void addExRound(Integer exRound) {
		if (exRound == null) {
			return;
		}
		this.exRound += exRound;
	}

	public void setDispel(Boolean dispel) {
		if (dispel == null) {
			return;
		}
		this.dispel = dispel;
	}

	public void setIgnAntiCtrl(Boolean ignAntiCtrl) {
		if (ignAntiCtrl == null) {
			return;
		}
		this.ignAntiCtrl = ignAntiCtrl;
	}

	public void addBuffHp(Long add) {
		if (add == null) {
			return;
		}
		this.buffHp += add;
	}

	public void addExPileMax(Integer add){
		if (add == null) {
			return;
		}
		this.exPileMax += add;
	}

	public void addExEffectArgs(String exArg) {
		if (StringUtils.isBlank(exArg)) {
			return;
		}
		if (exEffectArgs == null) {
			exEffectArgs = new ArrayList<>();
		}
		exEffectArgs.add(exArg);
	}

	public void addExBuff(List<ExBuffCfg> exBuffs){
		this.exBuffs = XT.merge(this.exBuffs, exBuffs);
	}
}
